package DemoText;

/**
 * 颜色分类
 */
public class LeetCode75 {
    public void sortColors(int[] nums) {
        int n = nums.length;
        int left = -1, right = n;
        for (int i = 0; i < right; ) {
            if (nums[i] < 1) swap(nums, ++left, i++);
            else if (nums[i] > 1) swap(nums, --right, i);
            else i++;
        }
    }
    public void swap(int[] nums, int a, int b) {
        int tmp = nums[a];
        nums[a] = nums[b];
        nums[b] = tmp;
    }
}
